package cqie.personal.frame.mapper;

import cqie.personal.frame.entity.CharacterInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Yeeeeee
 * @since 2021-09-08
 */
@Mapper
public interface CharacterInfoMapper extends BaseMapper<CharacterInfo> {
    @Insert("INSERT INTO user_character(user_id , character_id)" +
            "VALUE(#{uid},#{characterId})")
    Integer InsertUserCharacter(Integer uid ,Integer characterId);

    @Delete("DELETE FROM user_character WHERE user_id = #{uid}")
    void delOldCharacter(Integer uid);

    @Select(" SELECT GROUP_CONCAT(DISTINCT menu_id) as menu_id FROM character_menu " +
            " LEFT JOIN user_character ON " +
            " user_character.character_id = character_menu.character_id " +
            " LEFT JOIN user_info ON " +
            " user_character.user_id = user_info.uid " +
            " WHERE user_info.uid=#{uid} ")
    String getCharacterByUid(Integer uid);
}
